package http

import (
	"gitee.com/CrazyMage/lite-note/config"
	_ "gitee.com/CrazyMage/lite-note/docs" // Swagger docs.
	v1 "gitee.com/CrazyMage/lite-note/internal/controller/http/v1"
	"gitee.com/CrazyMage/lite-note/internal/service"
	"gitee.com/CrazyMage/lite-note/pkg/logger"
	"github.com/gin-gonic/gin"
	swaggerFiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"
)

func NewRouter(app *gin.Engine, cfg *config.Config,
	t service.User,
	n service.Note,
	l logger.Interface) {

	app.Use(gin.Logger())
	app.Use(gin.Recovery())

	// Swagger
	if cfg.Swagger.Enabled {
		app.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
	}

	apiV1Group := app.Group("/v1")
	{
		v1.NewUserRoutes(apiV1Group, t, l)
		v1.NewNoteRoutes(apiV1Group, n, l)
	}
}
